from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

class BlogList:
    driver=""
    url=""
    def __init__(self):
        self.driver=BlogDriver.driver
        #设置隐式等待
        self.driver.implicitly_wait(5)
        self.url="http://8.137.19.140:9090/blog_list.html"
        self.driver.get(self.url)

    # 测试 [登录状态] 用例
    def ListLogin(self):
        #（1）内容检查
        #检查 昵称 是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #检查 “查看全文” 按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a")
        #检查 博客标题，发布时间是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.title")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.date")
        BlogDriver.getScreenShot()
        #（2）测试 页面后退（到登录页面），再前进（回到博客列表页）是否成功
        self.driver.back()
        self.driver.forward()
        #检查是否有 博客体
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right")

    # 测试 [未登录状态] 用例
    def ListUnLogin(self):
        #未登录状态访问 博客列表页 是否跳转到登录页，并检查用户名密码框是否为空
        username= self.driver.find_element(By.CSS_SELECTOR,"#username").text
        password=self.driver.find_element(By.CSS_SELECTOR,"#password").text
        assert username=="" and password==""
        #屏幕截图
        BlogDriver.getScreenShot()















